public class Complex {
    private int x;  //实数
    private int y;  //虚数

    public Complex(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    /**
     * 当前复数与复数c相加 结果保存在result里
     * @param c
     * @return result
     */
    public Complex add(Complex c) {
        //用来保存结果
        Complex result = new Complex(0, 0);
        result.x = c.x + this.x;
        result.y = c.y + this.y;
        return result;
    }

    /**
     * 当前复数减去复数c 暂时用result保存
     * @param c
     * @return result
     */
    public Complex minus(Complex c) {
        Complex result = new Complex(0, 0);
        result.x = this.x - c.x;
        result.y = this.y - c.y;
        return result;
    }

    /**
     * 实现当前复数乘复数c
     * @param c
     * @return result
     */
    public Complex multiple(Complex c) {
        Complex result = new Complex(0, 0);
        result.x = this.x * c.x - this.y * c.y;
        result.y = this.y * c.x + this.x * c.y;
        return result;
    }

    /**
     * 实现当前复数除以复数c
     * @param c
     * @return result
     */
    public Complex divide(Complex c) {
        Complex result = new Complex(0, 0);
        if (c.x == 0 && c.y == 0) {
            //不能相除的情况
            return null;
        } else {
            // _c: 复数c的。。。不知道叫啥 分母有理化用的
            Complex _c = new Complex(c.x, -c.y);

            int denominator = c.x * c.x + c.y *c.y;
            Complex numerator = multiple(_c);
            result.x = numerator.x / denominator;
            result.y = numerator.y / denominator;
        }
        return result;
    }

    public String toString() {
        return this.x + "+" + this.y + "i";
    }
}
